package hotel.switchs.oversea.online.controller;

import com.alibaba.fastjson.JSONObject;
import hotel.base.oversea.constant.CallbackConstants;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.constant.enums.MtRequestUrlEnums;
import hotel.base.oversea.entity.SwitchHotelActiveTagEntity;
import hotel.base.oversea.utils.*;
import hotel.switchs.oversea.api.VO.request.BatchPushRoomVo;
import hotel.switchs.oversea.api.VO.request.RoomDataEntityVo;
import hotel.switchs.oversea.api.VO.request.RoomStatusModelVo;
import hotel.switchs.oversea.api.VO.request.SetRoomOnlineOfflineVo;
import hotel.switchs.oversea.api.entity.*;
import hotel.switchs.oversea.online.config.service.RedisService;
import hotel.switchs.oversea.online.mapper.*;
import hotel.switchs.oversea.online.service.SwitchBasicRoomTypeService;
import hotel.switchs.oversea.online.service.SwitchRoomPriceService;
import hotel.switchs.oversea.online.service.impl.SwitchRestTempaleUtilsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 便捷操作工具
 * @Author lmf
 * @Date 2020/6/10 13:39
 **/
@Slf4j
@RestController
@RequestMapping("/switchTool")
@Api(value = "SwitchToolController",tags = {"便捷操作工具"})
public class SwitchToolController {
    @Autowired
    private RedisService redisService;
    @Autowired
    private SwitchHotelUpMapper switchHotelUpMapper;
    @Autowired
    private SwitchRefuseOrderListMapper switchRefuseOrderListMapper;
    @Autowired
    private SwitchCreateRoomMapper switchCreateRoomMapper;
    @Autowired
    private SwitchBasicRoomTypeService switchBasicRoomTypeService;
    @Autowired
    private SwitchCreateRoomFailureMapper switchCreateRoomFailureMapper;
    @Autowired
    private SwitchRoomPriceService switchRoomPriceService;
    @Autowired
    private SwitchHotelActiveTagMapper switchHotelActiveTagMapper;
    @Autowired
    private SwitchOrderStatisticalMapper switchOrderStatisticalMapper;

    @Autowired
    private SwitchRestTempaleUtilsService switchRestTempaleUtilsService;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    SwitchHotelLevelMapper switchHotelLevelMapper;
    @Autowired
    SwitchHotelLevelLogMapper switchHotelLevelLogMapper;

    @Autowired
    SwitchOrderInfoMapper switchOrderInfoMapper;
    /**
     * 刪除緩存/增加緩存
     */
    @PostMapping("/operaCache")
    @ApiOperation(value = "操作緩存相關操作 ",notes="必须经过auth授权")
    public Result<Object> operaCache(@RequestBody JSONObject jsonObject){
        int db=jsonObject.getInteger("db");
        String key=jsonObject.getString("key");
        int genre=jsonObject.getInteger("genre");
        /**
         * 增加緩存/更新緩存/获取缓存
         */
        Object object=null;
        if(genre==1){
            String value=jsonObject.getString("value");
            redisService.set(db,key,value);
        }else if(genre==0) {
            object=redisService.get(key);
        }else if(genre==2){
            String value=jsonObject.getString("value");
            redisService.set(db,key,Integer.valueOf(value));
        }else{//刪除緩存
            if(redisService.exists(key)){
                redisService.remove(db,key);
            }
        }
        return new Result<>(object);
    }

    @SneakyThrows
    @PostMapping("/orderList")
    @ApiOperation(value = "拒單率統計 ",notes="必须经过auth授权")
    public Result<Object> orderList(){
        List<SwitchOrderStatisticalEntity> switchOrderStatisticalEntities=switchRefuseOrderListMapper.statisOrderNumList();
        for(SwitchOrderStatisticalEntity switchOrderStatisticalEntity:switchOrderStatisticalEntities){
            SwitchOrderStatisticalEntity switchOrderStatisticalEntity1=switchOrderStatisticalMapper.selectInfoByDate(switchOrderStatisticalEntity.getDate());
            if(!ObjectUtils.isEmpty(switchOrderStatisticalEntity1)){
                switchOrderStatisticalEntity.setRefuseNum(switchOrderStatisticalEntity1.getRefuseNum());
                switchOrderStatisticalEntity.setDelNum(switchOrderStatisticalEntity1.getDelNum());
            }else{
                String today=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
                if(!switchOrderStatisticalEntity.getDate().equals(today)){
                    if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getRefuseNum())){
                        switchOrderStatisticalEntity.setRefuseNum(0);
                    }
                    if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getCancelNum())){
                        switchOrderStatisticalEntity.setCancelNum(0);
                    }
                    if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getDelNum())){
                        switchOrderStatisticalEntity.setDelNum(0);
                    }
                    switchOrderStatisticalEntity.setRemark("");
                    switchOrderStatisticalMapper.insert(switchOrderStatisticalEntity);
                }
            }
            if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getRefuseNum())){
                switchOrderStatisticalEntity.setRefuseNum(0);
            }
            if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getCancelNum())){
                switchOrderStatisticalEntity.setCancelNum(0);
            }
            if(ObjectUtils.isEmpty(switchOrderStatisticalEntity.getDelNum())){
                switchOrderStatisticalEntity.setDelNum(0);
            }
            double rate=switchOrderStatisticalEntity.getRefuseNum().doubleValue()/switchOrderStatisticalEntity.getNum().doubleValue();
            double cancelRate=switchOrderStatisticalEntity.getCancelNum().doubleValue()/switchOrderStatisticalEntity.getNum().doubleValue();
            switchOrderStatisticalEntity.setRate(rate);
            switchOrderStatisticalEntity.setCancelRate(cancelRate);
            //获取延迟单数量
            Map<String,String> params=new HashMap<>();
            params.put("date",switchOrderStatisticalEntity.getDate());
            String url= CommonUrlConstants.MEITUAN_HOST+ MtRequestUrlEnums.GET_DEAL_ORDER_NUM.getUrl();
            Result<Object> result=switchRestTempaleUtilsService.sendPostRequesToMsg(url,params);
            if(ObjectUtils.isEmpty(result.getData())){
                switchOrderStatisticalEntity.setDelNum(0);
            }else{
                switchOrderStatisticalEntity.setDelNum(Integer.parseInt(result.getData().toString()));
                Example example=new Example(SwitchOrderStatisticalEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("date",switchOrderStatisticalEntity.getDate());
                switchOrderStatisticalMapper.updateByExampleSelective(switchOrderStatisticalEntity,example);
            }
        }
        return new Result<>(switchOrderStatisticalEntities);
    }
    /**
     * 延迟单月统计
     */
    @PostMapping("/orderListByMonth")
    @ApiOperation(value = "订单数据统计 ",notes="必须经过auth授权")
    public Result<Object> orderListByMonth(@RequestBody Map<String,String> map){
        if(!map.containsKey("year")){
            return new Result<>("请选择正确的年份");
        }
        List<Map<Integer,Object>> data= switchOrderStatisticalMapper.orderListByMonth(map);
        /*List<String> months=new ArrayList<>();
        List<String> datas=new ArrayList<>();
        List<String> rates=new ArrayList<>();
        if(!ObjectUtils.isEmpty(data)&&data.size()>0){
            data.forEach(e->{
                months.add(e.get("months")+"月份");
                Integer num= Integer.valueOf(e.get("num").toString());
                Integer total= Integer.valueOf(e.get("total").toString());
                datas.add(String.valueOf(e.get("num")));
                if(total==0){
                    rates.add("");
                }else{
                    BigDecimal b =new BigDecimal((num/total)*100);
                    double f1 =b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
                    log.info("=======f1的值为{}=======",f1);
                    rates.add(String.valueOf(f1));
                }
            });
        }
        Map<String,Object> result=new HashMap<>();
        result.put("month",months);
        result.put("data",datas);
        result.put("rates",rates);*/
        return new Result<>(data);
    }
    /***
     * @Author: lmf
     * @Date: 2021/3/29
     * 修改订单数据
     */
    @PostMapping("/editOrderInfo")
    @ApiOperation(value = "更新拒绝订单数据 ",notes="必须经过auth授权")
    public Result<Object> editOrderInfo(@RequestBody SwitchOrderStatisticalEntity switchOrderStatisticalEntity){
        Example example=new Example(SwitchOrderStatisticalEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("date",switchOrderStatisticalEntity.getDate());
        int flag=switchOrderStatisticalMapper.updateByExampleSelective(switchOrderStatisticalEntity,example);
        if(flag>0){
            return new Result<>();
        }else{
            return new Result<>("更新失败");
        }
    }


    @PostMapping("/upRoom")
    @ApiOperation(value = "下线产品 ",notes="必须经过auth授权")
    public Result<Object> upRoom(){
        List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectAllData();
        for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
            SetRoomOnlineOfflineVo setRoomOnlineOfflineVo=new SetRoomOnlineOfflineVo();
            setRoomOnlineOfflineVo.setRoomTypeId(switchCreateRoomEntity.getRoomId());
            setRoomOnlineOfflineVo.setHotelId(switchCreateRoomEntity.getHotelId());
            setRoomOnlineOfflineVo.setChannel("Ctrip");
            setRoomOnlineOfflineVo.setRoomStatus(1);
            switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
            setRoomOnlineOfflineVo.setChannel("Qunar");
            switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
        /*    try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
        }
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2020/11/30
     * 清除缓存,清黑名单的酒店+下线的酒店
     */
    @GetMapping("/delRoomCache")
    @ApiOperation(value = "清除缓存 ",notes="必须经过auth授权")
    public Result<Object> delRoomCache(@RequestParam(value = "genre",defaultValue = "0")Integer genre){
        //清除黑名单缓存
        List<SwitchCreateRoomEntity> switchCreateRoomEntities=new ArrayList<>();
        if(genre==0){
            switchCreateRoomEntities=switchCreateRoomMapper.selectHotelUpStatus(2);
        }else{//1.清除下线的酒店缓存
            switchCreateRoomEntities=switchCreateRoomMapper.selectHotelUpStatus(0);
        }
        for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
            //清除与售卖房型的关联数据
            String key= CommonConstants.SWITCH_SELLING_REDIS_BY_MT+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId();
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            //清除美团酒店id+美团产品id的key
            key=CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtGoodId();
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            //清除美团酒店id+美团房型id
            key=CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtRoomId();
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            //清除美团酒店id+美团产品id+餐食
            key=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtRoomId()+"_0";
            if(redisService.exists(key)){
                redisService.remove(key);
            }
            key=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+switchCreateRoomEntity.getMtHotelId()+"_"+switchCreateRoomEntity.getMtRoomId()+"_1";
            if(redisService.exists(key)){
                redisService.remove(key);
            }
        }
        return new Result<>();
    }
    /***
     * @Author: lmf
     * @Date: 2020/12/10
     * 关闭12.13-01.08
     */
    @GetMapping("/closeCreateRoomStatus")
    @ApiOperation(value = "关闭房态 ",notes="必须经过auth授权")
    public Result<Object> closeCreateRoomStatus(){
        BatchPushRoomVo batchPushRoomVo=new BatchPushRoomVo();
        List<SwitchCreateRoomEntity> switchCreateRoomEntities=switchCreateRoomMapper.selectAll();
        for(SwitchCreateRoomEntity switchCreateRoomEntity:switchCreateRoomEntities){
            List<RoomDataEntityVo> roomDataEntityVos=new ArrayList<>();
            RoomDataEntityVo roomDataEntityVo=new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            roomDataEntityVo.setStartDate("2020-12-14");
            roomDataEntityVo.setEndDate("2020-12-14");
            //roomDataEntityVo.setStartDate(DateUtil.getNextDays(3));
            // roomDataEntityVo.setEndDate("2021-01-08");
            RoomStatusModelVo roomStatusModelVo=new RoomStatusModelVo();
            roomStatusModelVo.setChannel("Ctrip");
            roomStatusModelVo.setSaleStatus(0);
            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
            roomDataEntityVos.add(roomDataEntityVo);
            batchPushRoomVo.setHotelId(switchCreateRoomEntity.getHotelId());
            batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
            Result<Map<String,String>> result=switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
            log.info("=======================推送结果为{}========================",result.getMsg());
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return new Result<>();
    }

    /****
     * @Author: lmf
     * @Date: 2020/12/22
     * 删除失效产品的缓存信息
     */
    @GetMapping("/deleteRoomFailure")
    @ApiOperation(value = "删除房态价格的缓存",notes="必须经过auth授权")
    public Result<Object> deleteRoomFailure(){
        List<SwitchCreateRoomFailureEntity> switchCreateRoomFailureEntities=switchCreateRoomFailureMapper.deleteRoomFailure();
        for(SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity:switchCreateRoomFailureEntities){
            String key=CallbackConstants.REDIS_ROW_GOODS_PRICE_CHECK+switchCreateRoomFailureEntity.getMtHotelId()+"_"+switchCreateRoomFailureEntity.getMtGoodId();
            if(redisService.exists(key)){
                log.info("======key {}删除中=========",key);
                redisService.remove(key);
            }else{
                log.info("======key {}忽略=========",key);
            }
            key=CallbackConstants.REDIS_ROW_GOODS_STATUS_CHECK+switchCreateRoomFailureEntity.getMtHotelId()+"_"+switchCreateRoomFailureEntity.getMtGoodId();
            if(redisService.exists(key)){
                log.info("======key {}删除中=========",key);
                redisService.remove(key);
            }else{
                log.info("======key {}忽略=========",key);
            }
            int day=3;
            if(redisService.isMember(CommonConstants.SWITCH_SALE_HOTEL_VIP,switchCreateRoomFailureEntity.getMtHotelId())){
                day=getDaysCommonBaseSetForVip();
            }else{
                day=getDaysCommonBaseSetForNormal();
            }
            //删除价格和房态缓存
            for(int i=0;i<day;i++){
                //删除房态
                key=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_STATUS_HEAD+switchCreateRoomFailureEntity.getMtHotelId()+"_"+switchCreateRoomFailureEntity.getMtGoodId()+"_"+DateUtil.getDateAfter(new Date(),i);
                if(redisService.exists(key)){
                    log.info("======key {}删除中=========",key);
                    redisService.remove(key);
                }else{
                    log.info("======key {}忽略=========",key);
                }
                //删除价格
                key=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_PRICE_HEAD+switchCreateRoomFailureEntity.getMtHotelId()+"_"+switchCreateRoomFailureEntity.getMtGoodId()+"_"+DateUtil.getDateAfter(new Date(),i);
                if(redisService.exists(key)){
                    log.info("======key {}删除中=========",key);
                    redisService.remove(key);
                }else{
                    log.info("======key {}忽略=========",key);
                }
                //删除价格
                key=CallbackConstants.REDIS_KEY_CALLBACK_CHANGE_PRICE_HEAD+switchCreateRoomFailureEntity.getMtHotelId()+"_"+switchCreateRoomFailureEntity.getMtGoodId()+"_"+DateUtil.getDateAfter(new Date(),i);
                if(redisService.exists(key)){
                    log.info("======key {}删除中=========",key);
                    redisService.remove(key);
                }else{
                    log.info("======key {}忽略=========",key);
                }
            }
        }
        return new Result<>();
    }
    /**
     * 获取普通酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForNormal() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_NORMAL_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForNormal获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询3天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 3;//有异常默认3天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }
        return returnDays;
    }
    /**
     * 获取优势酒店天数
     * @return
     */
    public Integer getDaysCommonBaseSetForVip() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("getDaysCommonBaseSetForVip获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询5天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 5;//有异常默认5天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }

        return returnDays;
    }
    /****
     * @Author: lmf
     * @Date: 2020/12/22
     * 删除失效产品的缓存信息
     */
    @GetMapping("/deletePricecache")
    @ApiOperation(value = "删除房态价格的缓存",notes="必须经过auth授权")
    public Result<Object> deletePricecache(){
        log.info("=========wo lai l ======");
        List<SwitchHotelActiveTagEntity>  switchHotelActiveTags=switchHotelActiveTagMapper.selectAll();
        for(SwitchHotelActiveTagEntity switchHotelActiveTagEntity:switchHotelActiveTags){
            Example example=new Example(SwitchHotelActiveTagEntity.class);
            Example.Criteria criteria=example.createCriteria();
            criteria.andEqualTo("hotelId",switchHotelActiveTagEntity.getHotelId());
            criteria.andEqualTo("roomId",switchHotelActiveTagEntity.getRoomId());
            int flag=switchHotelActiveTagMapper.deleteByExample(example);
            if(flag>0){
                log.info("=====刪除天天特價成功========");
                String key=CommonConstants.SWITCH_HOTEL_ACTIVE_TAG+switchHotelActiveTagEntity.getHotelId()+switchHotelActiveTagEntity.getRoomId();
                redisService.remove(key);
            }
        }
        return new Result<>();
    }

    /***
     * @Author: lmf
     * @Date: 2021/5/11
     * 模糊删除key
     */
    @PostMapping("/deleteKeyByLike")
    @ApiOperation(value = "模糊删除key",notes="必须经过auth授权")
    public Result<Object> deleteKeyByLike(@RequestBody Map<String,String> params){
        String pre=params.get("pre");
        Set<String> keys=stringRedisTemplate.keys(pre);
        if(!CollectionUtils.isEmpty(keys)){
            stringRedisTemplate.delete(keys);
        }
        return new Result<>();
    }

    /**
     * 删除价格公式缓存
     */
    @GetMapping("/deleteRelationCache")
    @ApiOperation(value = "删除价格公式缓存",notes="必须经过auth授权")
    public Result<Object> deleteRelationCache(){
        List<SwitchHotelUpEntity> switchHotelUpEntities=switchHotelUpMapper.selectAll();
        switchHotelUpEntities.forEach(e->{
            String key="switch_hotel_price_set_relation";
            String ctripKey=key+e.getHotelId()+"ctrip";
            if(redisService.exists(ctripKey)){
                redisService.remove(ctripKey);
            }
            String qunarKey=key+e.getHotelId()+"qunar";
            if(redisService.exists(qunarKey)){
                redisService.remove(qunarKey);
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        });
        return new Result<>();
    }
    /**
     * 判读某个元素是否set集合里面
     */
    @PostMapping("/judgeElementIsExisit")
    @ApiOperation(value = "判读某个元素是否set集合里面",notes="必须经过auth授权")
    public Result<Object> judgeElementIsExisit(@RequestBody Map<String,String> param){
        String pre=param.get("pre");
        Integer value=Integer.valueOf(param.get("value"));
        boolean f=redisService.isMember(pre,value);
        if(f){
            return new Result<>("存在");
        }else{
            return new Result<>("不存在");
        }
    }
    /**
     * 初始化vip/normal入库
     */
    @GetMapping("/saveHotelData")
    @ApiOperation(value = "初始化vip/normal入库",notes="必须经过auth授权")
    public Result<Object> saveHotelData(@RequestParam(name = "genre",defaultValue = "0")Integer genre){
        if(genre==0){
            Set<Object> set=redisService.getMembers(CommonConstants.SWITCH_SALE_HOTEL_VIP);
            set.forEach(e->{
                SwitchHotelLevelEntity switchHotelLevelEntity=new SwitchHotelLevelEntity();
                Example example=new Example(SwitchHotelLevelEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("mtHotelId", e);
                switchHotelLevelEntity.setCreateTime(new Date());
                switchHotelLevelEntity.setGenre(0);
                int count=switchHotelLevelMapper.selectCountByExample(example);
                if(count<1){
                    log.info("====不存在=========");
                    Integer hotelId=switchCreateRoomMapper.getHotelIdByMtHotelId((Integer) e);
                    if(!ObjectUtils.isEmpty(hotelId)) {
                        int isOrder = switchOrderInfoMapper.selectCountByHotelId(hotelId);
                        if (isOrder > 0) {
                            switchHotelLevelEntity.setIsOrder(1);
                        }
                        switchHotelLevelEntity.setHotelId(hotelId);
                        switchHotelLevelEntity.setMtHotelId((Integer) e);
                        SwitchHotelLevelLogEntity switchHotelLevelLogEntity = new SwitchHotelLevelLogEntity();
                        switchHotelLevelLogEntity.setCreateTime(new Date());
                        switchHotelLevelLogEntity.setGenre(0);
                        switchHotelLevelLogEntity.setMtHotelId((Integer) e);
                        switchHotelLevelLogEntity.setHotelId(hotelId);
                        switchHotelLevelLogEntity.setUpdateTime(new Date());
                        if (isOrder > 0) {
                            switchHotelLevelLogEntity.setIsOrder(1);
                        }
                        switchHotelLevelLogEntity.setRemark("优势酒店");
                        switchHotelLevelMapper.insert(switchHotelLevelEntity);
                        switchHotelLevelLogMapper.insert(switchHotelLevelLogEntity);
                    }
                }
            });
        }else{
            Set<Object> set=redisService.getMembers(CommonConstants.SWITCH_SALE_HOTEL_NORMAL);
            set.forEach(e->{
                SwitchHotelLevelEntity switchHotelLevelEntity=new SwitchHotelLevelEntity();
                Example example=new Example(SwitchHotelLevelEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("mtHotelId", e);
                switchHotelLevelEntity.setCreateTime(new Date());
                switchHotelLevelEntity.setGenre(1);
                int count=switchHotelLevelMapper.selectCountByExample(example);
                if(count<1){
                    log.info("====不存在=========");
                    Integer hotelId=switchCreateRoomMapper.getHotelIdByMtHotelId((Integer) e);
                    if(!ObjectUtils.isEmpty(hotelId)) {
                        int isOrder = switchOrderInfoMapper.selectCountByHotelId(hotelId);
                        if (isOrder > 0) {
                            switchHotelLevelEntity.setIsOrder(1);
                        }
                        switchHotelLevelEntity.setHotelId(hotelId);
                        switchHotelLevelEntity.setMtHotelId((Integer) e);
                        SwitchHotelLevelLogEntity switchHotelLevelLogEntity = new SwitchHotelLevelLogEntity();
                        switchHotelLevelLogEntity.setCreateTime(new Date());
                        switchHotelLevelLogEntity.setGenre(1);
                        switchHotelLevelLogEntity.setMtHotelId((Integer) e);
                        switchHotelLevelLogEntity.setHotelId(hotelId);
                        switchHotelLevelLogEntity.setUpdateTime(new Date());
                        if (isOrder > 0) {
                            switchHotelLevelLogEntity.setIsOrder(1);
                        }
                        switchHotelLevelLogEntity.setRemark("普通酒店");
                        switchHotelLevelMapper.insert(switchHotelLevelEntity);
                        switchHotelLevelLogMapper.insert(switchHotelLevelLogEntity);
                    }
                }
            });
        }
        return new Result<>();
    }



}
